package com.lxf.cloudcar.mapper;

import com.lxf.cloudcar.bean.UserCarBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Highlight;
import org.springframework.data.elasticsearch.annotations.HighlightField;
import org.springframework.data.elasticsearch.annotations.HighlightParameters;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 罗兴发
 * @data 2025/6/23 11:54
 * @description：es持久层
 */
@Component
public interface UserCarItemRepository extends ElasticsearchRepository<UserCarBean, String> {
    Page<UserCarBean> findAllByGoodName(String goodName, Pageable pageable);

    /**
     * 根据产品名称获取高亮数据信息
     * @param goodName 产品名称
     * @return 返回关键字高亮的结果集
     */
    @Highlight(
            fields = {@HighlightField(name = "goodName")},
            parameters = @HighlightParameters(preTags = {"<span style='color:red'>"}, postTags = {"</span>"}, numberOfFragments = 0)
    )
    List<SearchHit<UserCarBean>> findAllByGoodName(String goodName);
}